<template>
	<view class="addressList-wrap">
		<view class="addressList-item" v-for="(item, index) in dataList" :key="index" @click="selectAddress(item)">
			<view class="addressList-item-default" v-if="item.isDefault">默认</view>
			<view class="addressList-item-layer">
				<view class="addressList-item-info">
					<view class="item-info-top">
						<view class="item-info-name">{{ item.name }}</view>
						<view class="item-info-phone">{{ item.phone }}</view>
					</view>
					<view class="item-info-address">{{ item.province + item.city + item.district + item.address }}</view>
				</view>
				<view class="addressList-item-cut"></view>
				<image
					class="addressList-item-edit"
					@click.stop="gotoRouter('/pages-member/addressInfo/addressInfo?id=' + item.id)"
					src="http://k8s.vendingtech.vip/images/updates@2x.png"
				></image>
			</view>
		</view>

		<u-empty-state v-if="dataList.length == 0" value="你还没有添加地址"></u-empty-state>

		<u-bottom-button value="添加地址" @click="gotoRouter('/pages-member/addressInfo/addressInfo')"></u-bottom-button>
	</view>
</template>

<script>
import uBottomButton from '@/components/u-bottom-button/u-bottom-button.vue';
import uEmptyState from '@/components/u-empty-state/u-empty-state.vue';
import { mapState, mapMutations } from 'vuex';
export default {
	components: {
		uEmptyState,
		uBottomButton
	},
	data() {
		return {
			pageType: null, // null展示模式  1选择模式
			id: null,
			dataList: null
		};
	},
	onLoad(option) {
		this.pageType = option.type ? option.type : null;
	},
	onShow() {
		this.addressList();
	},
	methods: {
		...mapMutations({
			setUserAddress: 'setUserAddress'
		}),

		//选择地址
		selectAddress(item) {
			if (this.pageType == 1) {
				this.setUserAddress(item);
				uni.navigateBack({
					delta: 1
				});
			}
		},

		//地址列表
		addressList() {
			this.$api.addressList({}).then(res => {
				if (res.code == 200) {
					this.dataList = res.result;
				} else {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
				}
			});
		}
	}
};
</script>

<style lang="less">
@import './addressList.less';
</style>
